package com.xinxin.leetcode.problem530;

import com.xinxin.leetcode.common.TreeNode;
import com.xinxin.leetcode.common.TreeUtil;

/**
 * @author ShiXinXin
 * @date 2020-01-13 2:10
 */
class Solution {
    int a1 = -1, res = Integer.MAX_VALUE;

    void midTree(TreeNode root) {
        if (root == null) {
            return;
        }
        midTree(root.left);
        if (a1 == -1) {
            a1 = root.val;
        } else {
            res = Math.min(root.val - a1, res);
            a1 = root.val;
        }
        midTree(root.right);
    }

    public int getMinimumDifference(TreeNode root) {
        midTree(root);
        return res;
    }

    public static void main(String[] args) {
        int[] arr = {1, 0, 3, 2, 0, 0, 0};
        TreeNode root = TreeUtil.createTree(arr);
        System.out.println(new Solution().getMinimumDifference(root));
    }
}
